<?php
/**
 * 下级机构列表
 * User: hgq
 * Date: 2016/10/31
 * Time: 上午9:35
 */
use yii\helpers\Url;
$web = Url::base();
?>
<script type="text/javascript" src="<?= $web ?>/js/jquery.tooltips.js"></script>
<script type="application/javascript">

    $(function ($) {

        //初始化checkbox样式
        $('.square-blue input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });

        //选择框 全选 全消
        var isChkAllClickinst = false;
        $('#chkAllinst').on('ifClicked', function (event) {
            isChkAllClickinst = true;
        });

        $('#chkAllinst').on('ifChecked ifUnchecked', function (event) {
            if (isChkAllClickinst == false) {
                return;
            }
            if (event.type == 'ifChecked') {
                $('input:checkbox[name=clildInstlist]').iCheck('check');
            } else {
                $('input:checkbox[name=clildInstlist]').iCheck('uncheck');
            }

            isChkAllClickinst = false;
        });

        var isItemClickinst = false;
        $('input:checkbox[name=clildInstlist]').on('ifClicked', function (event) {
            isItemClickinst = true;
        });
        $('input:checkbox[name=clildInstlist]').on('ifChecked ifUnchecked', function (event) {
            if (isItemClickinst == false) {
                return;
            }
            if ($('input:checkbox[name=clildInstlist]:checked').length == $('input:checkbox[name=clildInstlist]').length) {
                $('#chkAllinst').iCheck('check');
            } else {
                $('#chkAllinst').iCheck('uncheck');
            }
            isItemClickinst = false;
        });

    });

</script>

<div id="body_table">
    <div class="table-responsive">
        <table class="table table-bordered table-hover table-condensed" style=" margin-top: 5px">
            <thead class="nowrap">
            <tr>
                <th style="width:30%">机构编码</th>
                <th style="width:60%">机构名称</th>
                <th style="width:10%">
                    <div class="checkbox square-blue">
                        <input type="checkbox" id="chkAllinst">
                    </div>
                </th>
            </tr>
            </thead>
            <tbody>
            <?php
            if ($list != null && $list != '') {
                for ($i = 0; $i < count($list); $i++) {
                    ?>
                    <tr>
                        <td><?= $list[$i]['code'] ?></td>
                        <td><?= $list[$i]['name'] ?></td>
                        <td style=" vertical-align:middle;">
                            <div class="checkbox square-blue">
                                <input type="checkbox" name="clildInstlist" data-child-institution-code="<?= $list[$i]['code'] ?>">
                            </div>
                        </td>
                    </tr>
                    <?php
                }
            }
            ?>
            </tbody>
        </table>
    </div>
</div>